using System;
using System.Collections.Generic;
using System.Text;
using Universe.Farm.Service.Mesages;

namespace Universe.Farm.Service
{
    class FarmAdminService : MarshalByRefObject, IFarmAdminService
    {
        private ConfigurationContainer _Config;

        public FarmAdminService(ConfigurationContainer config)
        {
            _Config = config;
        }

        public void SetVisibility(ServicesScope scope, bool visibility)
        {
            IStateStorage stateStorage = _Config.ResolveRequired<IStateStorage>();
            TimeStampIO io = new TimeStampIO(stateStorage, "Generic");
            TimeStamp ts = io.GetNext();

            SetVisibilityMessage byeMessage = new SetVisibilityMessage(new MessageHeader(CommunicationParameters.ComputerID, ts), scope, visibility);
            foreach (DeliveryAgent agent in _Config.ResolveRequired<List<DeliveryAgent>>())
                agent.Deliver(byeMessage);
        }
    }
}
